package com.tedu.checkIn.service.impl;

import com.tedu.checkIn.mapper.BedMapper;
import com.tedu.checkIn.mapper.RecordMapper;
import com.tedu.checkIn.pojo.dto.BedQuery;
import com.tedu.checkIn.pojo.dto.RecordParam;
import com.tedu.checkIn.pojo.dto.RecordQuery;
import com.tedu.checkIn.pojo.entity.Bed;
import com.tedu.checkIn.pojo.entity.Record;
import com.tedu.checkIn.pojo.vo.BedVO;
import com.tedu.checkIn.pojo.vo.RecordVO;
import com.tedu.checkIn.service.RecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class RecordServiceImpl implements RecordService {
    @Autowired
    RecordMapper recordMapper;
    @Autowired
    BedMapper bedMapper;

    @Override
    public void saveRecord(RecordParam recordParam) {
        log.debug("保存入住信息业务，参数={}",recordParam);
        Record record=new Record();
        BeanUtils.copyProperties(recordParam,record);
        if (record.getId()==null){
            record.setCreateTime(new Date());
            record.setStatus("30");
            record.setReviewStatus("10");
            recordMapper.insert(record);
        }else {
            record.setUpdateTime(new Date());
            recordMapper.update(record);
        }
    }

    @Override
    public List<RecordVO> selectRecord(RecordQuery recordQuery) {
        log.debug("查询入住信息列表业务，参数={}",recordQuery);
        List<RecordVO> list=recordMapper.select(recordQuery);
        for (RecordVO recordVO : list) {
            BedQuery bedQuery = new BedQuery();
            bedQuery.setId(recordVO.getBedId());
            List<BedVO> bedList = bedMapper.selectBed(bedQuery);
            recordVO.setBedName(bedList.get(0).getName());
        }
        log.debug("查询个人物品业务，入数={},出参{}",recordQuery,list);
        return list;
    }

    @Override
    public void delete(Integer id) {
        log.debug("删除入住信息业务，参数={}",id);
        recordMapper.delete(id);
    }
}
